package com.nf.health.app.activity.doctor_advice.adapter;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.intervention_details.activity.HealthSurveyActivity;
import com.nf.health.app.activity.doctor_advice.bean.AdviceDetail;
import com.nf.health.app.utils.ActivityUtils;

import java.util.List;

/**
 * Created by fei on 2016/11/25.
 * 医嘱详情信息 问题 列表的adapter
 */

public class SubDoctorAdviceByIdAdapter extends BaseAdapter {
    private Context context;
    private String  state;
    private String   questionId;
    private List<AdviceDetail.QuestionListBean.QuestionBean>   datas;
    public SubDoctorAdviceByIdAdapter(Context context, List<AdviceDetail.QuestionListBean.QuestionBean> datas,String state,String  questionId) {
        this.context = context;
        this.datas = datas;
        this.state = state;
        this.questionId = questionId;
    }
    public void setSubDataChanged(List<AdviceDetail.QuestionListBean.QuestionBean> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        if(datas!=null&&datas.size()>0){
            return datas.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int arg0) {
        return datas.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }

    @Override
    public View getView(final int position, View convertview, ViewGroup arg2) {
         ViewHolder holder = null;
        final AdviceDetail.QuestionListBean.QuestionBean  questionListBean = datas.get(position);
        if (convertview==null) {
            convertview = View.inflate(context, R.layout.item_doctoradvicebyid_sub, null);
            holder = new ViewHolder();
            holder.tv_advice_question = (TextView) convertview.findViewById(R.id.tv_advice_question);
            holder.tv_advice_answer = (TextView) convertview.findViewById(R.id.tv_advice_answer);
            holder.ll_question = (LinearLayout) convertview.findViewById(R.id.ll_question);
            convertview.setTag(holder);
        } else {
            holder = (ViewHolder) convertview.getTag();
        }
        holder.tv_advice_question.setText(TextUtils.isEmpty(questionListBean.getQuestion())? "" :questionListBean.getQuestion());
        //设置问题的状态
      //  model.state.intValue==1?(itemModel.ans.intValue==1 ? @"是":@"否"):@"未回复"
        String answer = "";
        if(state.equals("0")){
            answer = "未回复";
        }else if(state.equals("1")){
            if(TextUtils.isEmpty(questionListBean.getAns())){
                answer = "未回复";
            }else if(questionListBean.getAns().equals("1")){
                answer = "是";
            }else{
                answer = "否";
            }
        }
        holder.tv_advice_answer.setText(answer);
        holder.ll_question.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString("id", questionId);
                bundle.putString("type", "2");
                ActivityUtils.showActivity(context, HealthSurveyActivity.class, bundle);

            }
        });
        return convertview;
    }
      class ViewHolder{
        TextView tv_advice_question,tv_advice_answer;
          LinearLayout ll_question;
    }



}
